# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Vlad M. <vlad@archlinux.net>

pkgname=borg
_pkgname=borgbackup
pkgver=1.2.6
pkgrel=1
pkgdesc='Deduplicating backup program with compression and authenticated encryption'
url='https://borgbackup.github.io/'
license=('BSD')
arch=('loong64' 'x86_64')
depends=('acl' 'lz4' 'openssl' 'xz' 'zstd' 'python' 'python-packaging'
         'python-msgpack')
optdepends=('openssh: repositories on remote hosts'
            'python-llfuse: mounting backups as a FUSE file system')
makedepends=('python-build' 'python-installer' 'python-setuptools' 'python-setuptools-scm' 'python-pkgconfig'
             'python-sphinx' 'python-guzzle-sphinx-theme' 'python-wheel' 'cython')
checkdepends=('python-pytest' 'python-dateutil')
provides=('borgbackup')
replaces=('borgbackup')
source=("https://github.com/$_pkgname/$pkgname/releases/download/$pkgver/$_pkgname-$pkgver.tar.gz"{,.asc})
sha256sums=('b7a6f8f086039eeec79070b914f3c651ed7f3612c965374af910d277c7a2139d'
            'SKIP')
validpgpkeys=('6D5BEF9ADD2075805747B70F9F88FB52FAF7B393') # Thomas Waldmann <tw@waldmann-edv.de>

build() {
  cd "$_pkgname-$pkgver"
  python -m build --wheel --no-isolation
}

check() {
  cd "$_pkgname-$pkgver/build/lib.linux-$CARCH-cpython-"*/
  PYTHONPATH=$PWD PYTHONDONTWRITEBYTECODE=1 pytest -k 'not benchmark'
}

package() {
  cd "$_pkgname-$pkgver"
  python -m installer --destdir="$pkgdir" dist/*.whl

  install -Dm644 scripts/shell_completions/bash/borg \
    "$pkgdir/usr/share/bash-completion/completions/borg"
  install -Dm644 scripts/shell_completions/fish/borg.fish \
    "$pkgdir/usr/share/fish/vendor_completions.d/borg.fish"
  install -Dm644 scripts/shell_completions/zsh/_borg "$pkgdir/usr/share/zsh/site-functions/_borg"

  install -Dm644 -t "$pkgdir/usr/share/man/man1/" "docs/man/"*.1
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
